package demo.kafka;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.listener.MessageListener;
import org.springframework.stereotype.Service;

/**
 * @description 消息消费实现类
 * @author zhouxinghuai
 * @date 2018-10-16
 */
@Service
public class ConsumerListenerService implements MessageListener<Integer, String> {

    @Override
    public void onMessage(ConsumerRecord<Integer, String> consumerRecord) {
        //根据不同topic，消费
        if ("test".equals(consumerRecord.topic())) {
            //topic:test
            System.err.println("topic:test -> " + consumerRecord.value());
        } else if ("test1".equals(consumerRecord.topic())) {
            //topic:test1
            System.err.println("topic:test1 -> " + consumerRecord.value());
        }
    }
}
